#include "genfiltervaluesdialog.h"
#include "ui_genfiltervaluesdialog.h"

GenFilterValuesDialog::GenFilterValuesDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::GenFilterValuesDialog)
{
    ui->setupUi(this);

}

GenFilterValuesDialog::~GenFilterValuesDialog()
{
    delete ui;
}

QStringList GenFilterValuesDialog::values(QString text)
{
    QStringList values;
    auto lines = text.split("\n");
    auto left = ui->sb_left->value();
    auto right = ui->sb_right->value();

    foreach (auto line, lines) {
        auto splits = line.split(QRegExp("\\s+"));
        if (splits.count() > right) {
            auto var_index_left = line.indexOf(splits.at(left));
            auto var_index_right = line.indexOf(splits.at(right)) + splits.at(right).length();

            values << line.mid(var_index_left, var_index_right - var_index_left);
        }
    }
    return values;
}

int GenFilterValuesDialog::index()
{
    return ui->sb_left->value();;
}


void GenFilterValuesDialog::on_sb_left_valueChanged(int arg1)
{
    if (ui->sb_left->value() > ui->sb_right->value()) {
        ui->sb_right->setValue(ui->sb_left->value());
    }
}


void GenFilterValuesDialog::on_sb_right_valueChanged(int arg1)
{
    if (ui->sb_left->value() > ui->sb_right->value()) {
        ui->sb_left->setValue(ui->sb_right->value());
    }
}

